package edu.zzu.mapper;

import com.sun.xml.internal.bind.v2.runtime.reflect.Lister;
import edu.zzu.Entity.DLS;
import edu.zzu.Entity.Delivery;
import edu.zzu.Entity.Package;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface PackageMapper extends Mapper<Package> {

    @Select("select receiver from Package where ReceiverTel=#{tel}")
    String queryReceiverByTel(String tel);

    @Select("select sender from Package where senderTel=#{tel}")
    String querySenderByTel(String tel);

    @Select("select * from Package where senderTel=#{tel}")
    List<Package> selectPackageBySenderTel(String tel);

    @Select("select * from Package where receiverTel=#{tel}")
    List<Package> selectPackageByReceiverTel(String tel);

    @Update("update Package set status=#{status} ,handler=#{handler},updateTime=#{updateTime}," +
            "transNodeId=#{transNodeId},x=#{x},y=#{y} where id=#{id}")
    int updatePackageStatus(@Param("id")String id,@Param("status") Integer status,@Param("handler")Long handler,
                            @Param("updateTime")String updateTime,@Param("transNodeId")Long transNodeId,
                            @Param("x")Float x,@Param("y")Float y);

    @Select("select id,updateTime,sender,senderTel,senderAddr from Package where sourceNode=#{regionCode} and status=0")
    @Results({
            @Result(column = "id",property = "packageId"),
            @Result(column = "updateTime",property = "submitTime"),
            @Result(column = "sender",property = "sender"),
            @Result(column = "senderTel",property = "senderTel"),
            @Result(column = "senderAddr",property = "senderAddr")
    })
    List<DLS> selectDLSByRegionCode(String regionCode);

    @Select("select id,updateTime,receiver,receiverTel,receiverAddr from Package where handler=#{handler} and status=4")
    @Results({
            @Result(column = "id",property = "packageId"),
            @Result(column = "updateTime",property = "updateTime"),
            @Result(column="receiver",property = "receiver"),
            @Result(column = "receiverTel",property = "receiverTel"),
            @Result(column = "receiverAddr",property = "receiverAddr")
    })
    List<Delivery> selectDeliveryByHandler(Long id);

    @Select("select count(id) from Package where transNodeId=#{transNodeId}")
    Long selectPackageAmountByTransNodeId(Long transNodeId);

    @Select("select * from Package where transNodeId=#{transNOdeId}")
    List<Package> selectPackagesOfTransNode(Long transNodeId);

    @Select("select * from Package where status=#{status}")
    List<Package> selectPackagesByStatus(Integer status);
}
